import {Injectable} from '@angular/core';
import {Headers, Http} from '@angular/http';
import {AppConfig} from '../config';
import {SubArray} from '../entity/subarray.model';
import {InterceptorService} from './interceptor/interceptor-service';

@Injectable()
export class SubArrayService {

  private readonly param = 'subArrays';

  private get url(): string {
    return `${AppConfig.APP_RESTFUL}/${this.param}`;
  }

  constructor(
    private http: InterceptorService) {
  }

  getSubArrays(): Promise<SubArray[]> {
    return this.http.get(this.url)
      .toPromise()
      .then(response => response.data as SubArray[])
      .catch(this.handleError);
  }

  private handleError(error: any): Promise<any> {
    // console.error('An error occurred', error); // for demo purposes only
    return Promise.reject(error.message || error);
  }

}


// WEBPACK FOOTER //
// ./src/app/service/sub-array.service.ts
